package lv.yasa.helper;

import java.io.File;
import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.widget.Toast;

public class SoundHelper {

	static SoundHelper instance;
	MediaPlayer mediaPlayer;
	
	Activity currentActivity;
	
	public static void init(Activity currentActivity)
	{
		instance = new SoundHelper();
		
		instance.mediaPlayer = new  MediaPlayer();
		instance.currentActivity = currentActivity;		
	}
	
	public static SoundHelper getInstance()
	{
		return instance;
	}
	
	public void play(String filename)
	{
		String path = FSHelper.getFilePath(filename);
		try {
			instance.mediaPlayer.setDataSource(path);
			instance.mediaPlayer.prepare();
			mediaPlayer.start();
			Toast.makeText(currentActivity, path, Toast.LENGTH_LONG).show();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Toast.makeText(currentActivity, e.toString(), Toast.LENGTH_LONG).show();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Toast.makeText(currentActivity, e.toString(), Toast.LENGTH_LONG).show();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			Toast.makeText(currentActivity, e.toString(), Toast.LENGTH_LONG).show();
		}			
	}
}
